package com.charles.springcloud.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Date;

/**
 * @Author: 风中灵劲草
 * @Date: 2021/08/18/15:12
 * @Description: 全局自定义过滤器
 */
@Component
@Slf4j
public class GateWayFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        log.info("****GateWayFilter:" + new Date());
//        String username = exchange.getRequest().getQueryParams().getFirst("username");
//        if (Strings.isEmpty(username)){
//            log.info("该用户不存在,o(╥﹏╥)o");
//            exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);
//            return exchange.getResponse().setComplete();
//        }
//        return chain.filter(exchange);
        return null;
    }

    /**
     * 过滤器加载的顺序 越小,优先级别越高
     * */

    @Override
    public int getOrder() {
        return 0;
    }
}
